using System.ComponentModel;
using Meebey.SmartIrc4net;

namespace Thunder.Irc.Parser.Default
{
    /// <summary>
    /// Handles the Name message 
    /// </summary>
    internal class MessageParserName : MessageParser
    {
        /// <summary>
        /// Gets the type of message handled by the parser
        /// </summary>
        public override ReceiveType MessageType
        {
            get { return ReceiveType.Name; }
        }

        /// <summary>
        /// This method is invoked during message parsing.
        /// </summary>
        /// <param name="args">The <see cref="CancelMessageProcessingEventArgs"/> containing the message to be passed</param>
        /// <remarks>You can cancel further processing of the message by setting the <see cref="CancelEventArgs.Cancel"/> to true</remarks>
        protected override void ParseCore(CancelMessageProcessingEventArgs args)
        {
            if (args.MessageData.ReplyCode == ReplyCode.NamesReply)
            {
                string[] names = args.MessageData.Message.Split(" ".ToCharArray());
                foreach (string name in names)
                {
                    this.Manager.AddMember(args.MessageData.Channel, name);
                }
            }
            else
            {
                IMessageParser parser = new MessageParserDefault();
                parser.Initialize(this.Manager);
                parser.Parse(args);
            }
        }
    }
}